package com.ruoyi.courseRecords.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.courseRecords.domain.UoocCourse;
import com.ruoyi.courseRecords.service.IUoocCourseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 课程信息Controller
 * 
 * @author LGJ
 * @date 2025-07-08
 */
@RestController
@RequestMapping("/course/records")
public class UoocCourseController extends BaseController
{
    @Autowired
    private IUoocCourseService uoocCourseService;

    /**
     * 查询课程信息列表
     */
    @PreAuthorize("@ss.hasPermi('course:records:list')")
    @GetMapping("/list")
    public TableDataInfo list(UoocCourse uoocCourse)
    {
        startPage();
        List<UoocCourse> list = uoocCourseService.selectUoocCourseList(uoocCourse);
        return getDataTable(list);
    }    
    /**
     * 根据课程ID查询课程信息列表
     */
    @PreAuthorize("@ss.hasPermi('course:records:list')")
    @GetMapping("/course/{courseId}")
    public TableDataInfo getByCourseId(@PathVariable("courseId") Long courseId) {
        UoocCourse query = new UoocCourse();
        query.setCourseId(courseId);
        startPage();
        List<UoocCourse> list = uoocCourseService.selectUoocCourseList(query);
        return getDataTable(list);
    }
    /**
     * 根据教师ID查询课程信息列表
     */
    @PreAuthorize("@ss.hasPermi('course:records:list')")
    @GetMapping("/teacher/{teacherId}")
    public TableDataInfo getByTeacherId(@PathVariable("teacherId") Long teacherId) {
        UoocCourse query = new UoocCourse();
        query.setTeacherId(teacherId);
        startPage();
        List<UoocCourse> list = uoocCourseService.selectUoocCourseList(query);
        return getDataTable(list);
    }
    /**
     * 根据课程名称查询课程信息列表
     */
    @PreAuthorize("@ss.hasPermi('course:records:list')")
    @GetMapping("/search/{courseName}")
    public TableDataInfo searchByCourseName(@PathVariable("courseName") String courseName) {
        UoocCourse query = new UoocCourse();
        query.setCourseName(courseName);
        startPage();
        List<UoocCourse> list = uoocCourseService.selectUoocCourseList(query);
        return getDataTable(list);
    }

    /**
     * 导出课程信息列表
     */
    @PreAuthorize("@ss.hasPermi('course:records:export')")
    @Log(title = "课程信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UoocCourse uoocCourse)
    {
        List<UoocCourse> list = uoocCourseService.selectUoocCourseList(uoocCourse);
        ExcelUtil<UoocCourse> util = new ExcelUtil<UoocCourse>(UoocCourse.class);
        util.exportExcel(response, list, "课程信息数据");
    }

    /**
     * 获取课程信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('course:records:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId)
    {
        return success(uoocCourseService.selectUoocCourseByRecordId(recordId));
    }

    /**
     * 新增课程信息
     */
    @PreAuthorize("@ss.hasPermi('course:records:add')")
    @Log(title = "课程信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UoocCourse uoocCourse)
    {
        int result = uoocCourseService.insertUoocCourse(uoocCourse);
//      return toAjax(uoocCourseService.insertUoocCourse(uoocCourse));
        return success(uoocCourse); // 返回完整对象
    }

    /**
     * 修改课程信息
     */
    @PreAuthorize("@ss.hasPermi('course:records:edit')")
    @Log(title = "课程信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UoocCourse uoocCourse)
    {
        return toAjax(uoocCourseService.updateUoocCourse(uoocCourse));
    }

    /**
     * 删除课程信息
     */
    @PreAuthorize("@ss.hasPermi('course:records:remove')")
    @Log(title = "课程信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds)
    {
        return toAjax(uoocCourseService.deleteUoocCourseByRecordIds(recordIds));
    }
}
